home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / c_speed2d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.0 KB  |  199 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef ZOMPLEX
  12.  
  13. typedef zomplex this_type;
  14. typedef double this_half;
  15.  
  16. #define        TOLERANCE        DTOLERANCE
  17. #define        THIS_GEN        zgen_
  18. #define        THIS_FFTI        zfft2di
  19. #define        THIS_SCAL        zscal2d
  20. #define        THIS_FFT        zfft2d
  21.  
  22. #endif
  23.  
  24. #ifdef COMPLEX
  25.  
  26. typedef complex this_type;
  27. typedef float this_half;
  28.  
  29. #define        TOLERANCE        STOLERANCE
  30. #define        THIS_GEN        cgen_
  31. #define        THIS_FFTI        cfft2di
  32. #define        THIS_SCAL        cscal2d
  33. #define        THIS_FFT        cfft2d
  34.  
  35. #endif
  36.  
  37. /*    */
  38.  
  39. void inimat_();
  40. void GetArguments();
  41. void get_values();
  42.  
  43. int min_size, max_size, inc_size, size, size_x, size_y, ld;
  44. this_type *pa, *pSave, *pt;
  45.  
  46. int is_timing;
  47.  
  48. static     long z_sec, z_usec;
  49. static int first_time = 1;
  50.  
  51. float second()
  52. {
  53.         struct timeval s_val;
  54.     struct timezone s_z;
  55.     float time;
  56.     long n_sec, n_usec;
  57.         gettimeofday(&s_val, &s_z);
  58.     n_sec = s_val.tv_sec;
  59.     n_usec = s_val.tv_usec;
  60.     if( first_time ) {
  61.         z_sec = n_sec;
  62.         z_usec = n_usec;
  63.         first_time =0;
  64.     }
  65.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  66.     return( time );
  67. }
  68.  
  69. main(argc,argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.     int i, j, k, n_total, is_wrong, nx, ny, inc, n_times, n_flops;
  74.     double x, y, t, emax;
  75.     this_half ratio;
  76.  
  77. /* ******************************************************* */
  78.     GetArguments( argc, argv);
  79. /* ******************************************************* */
  80.  
  81.     srandom( (123*getpid()) | 0x01);
  82.  
  83.     for( size=min_size ; size <= max_size ; size += inc_size) { 
  84.  
  85.     nx = (size_x) ? size_x : size;
  86.     ny = (size_y) ? size_y : size;
  87.     ld = nx+1;
  88.     n_total = (ld)*ny;
  89.     pa = (this_type *)malloc( (n_total + ny + nx + 2*FACTOR_SPACE) * sizeof(this_type));
  90.     if( !(pa) ) {
  91.         fprintf( stderr, "Could not allocate ... Exiting\n");
  92.         exit (-1);
  93.     }
  94.  
  95.     fflush(stdout);
  96.  
  97.     printf( "%4d  ", size);
  98.  
  99.     n_flops = (int) (5. * (double)(nx*ny) * (log((double)(nx*ny))/log(2.)));
  100.     n_times = (int) (MAX_FLOPS / (double)n_flops);
  101.     if(n_times < 1) n_times =1;
  102.     ratio = 1./(double)(nx*ny);
  103. /* *******************************************************
  104. ******************************************************* */
  105.     pSave = pa + n_total;
  106.  
  107.     THIS_GEN(pa, &n_total);
  108.     pSave = THIS_FFTI( nx,ny, pSave);
  109.  
  110.     inc =1 ;
  111.  
  112.     t = second();
  113.     for ( i = 0 ; i < n_times ; i++)  {
  114.         inc = -1;
  115.          THIS_FFT( inc, nx, ny, pa, ld, pSave);
  116.         inc = 1;
  117.          THIS_FFT( inc, nx, ny, pa, ld, pSave);
  118.         THIS_SCAL( nx, ny, ratio, pa, ld);
  119.     }
  120.     t = second() - t;
  121.  
  122.     if( is_timing)
  123.         x = t / (double)(2*n_times);
  124.     else
  125.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  126.     printf("%6.3g  ", x);
  127. /* *******************************************************
  128. ******************************************************* */
  129.     printf("\n");
  130.     free(pa);
  131.     }
  132.     return (0);
  133. }
  134.  
  135. int is_random;
  136.  
  137. void GetArguments( argc, argv)
  138. int argc;
  139. char *argv[];
  140. {
  141.     int i, j, k;
  142.     int nerror = 0;
  143.  
  144. #define ON    1
  145.  
  146.     max_size = MAX_SIZE;
  147.     min_size = MIN_SIZE;
  148.     inc_size = INC_SIZE;
  149.  
  150.     is_timing = 0;
  151.     size_x = 0;
  152.     size_y = 0;
  153.  
  154. /* ******************************************************* */
  155.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  156.     if( argv[i][0] == '-') {
  157.         switch ( argv[i][1]) {
  158.         case 'x' :
  159.         case 'X' :  
  160.                 if( i+1 > argc)
  161.                 nerror = ON;
  162.                 else
  163.                 size_x = atoi( argv[++i]);
  164.                 break;
  165.         case 'y' :
  166.         case 'Y' :  
  167.                 if( i+1 > argc)
  168.                 nerror = ON;
  169.                 else
  170.                 size_y = atoi( argv[++i]);
  171.                 break;
  172.         case 't' :
  173.         case 'T' :  
  174.                 is_timing = 1;
  175.                 break;
  176.         default  :  nerror = ON;
  177.         }
  178.     }
  179.     else {
  180.         if( i+1 > argc)
  181.         nerror = ON;
  182.         else { 
  183.         min_size = atoi( argv[i++]);
  184.         max_size = atoi( argv[i++]);
  185.         inc_size = atoi( argv[i]);
  186.         }
  187.     }
  188.     }
  189.     if( nerror == ON) {
  190.     fprintf( stderr, 
  191.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  192.     exit(-1);
  193.     }
  194.     if ( is_timing) 
  195.         fprintf( stderr, "Checking Performance   in Secs\n");
  196.     else
  197.         fprintf( stderr, "Checking Performance   in Mflops\n");
  198. }
  199.